package com.sylli.oeuf.server.game.logic.skill;

import java.util.ArrayList;
import java.util.Collection;

import com.sylli.oeuf.server.game.logic.ActionProduct;
import com.sylli.oeuf.server.game.logic.BattleActor;
import com.sylli.oeuf.server.game.logic.CastingTarget;
import com.sylli.oeuf.server.game.logic.EventParameter;
import com.sylli.oeuf.server.game.logic.Skill;
import com.sylli.oeuf.server.game.logic.action.ActionAddBuff;
import com.sylli.oeuf.server.game.logic.action.CombatLog;
import com.sylli.oeuf.server.game.logic.action.Damage;
import com.sylli.oeuf.server.game.logic.action.Healing;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueElement;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueFlag;
import com.sylli.oeuf.server.game.logic.invocation.InvocationAction;
import com.sylli.oeuf.server.game.logic.invocation.InvocationCondition;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEntry;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEvent;
import com.sylli.oeuf.server.game.logic.skill.passive.Vampire_HellBlue_Buff;

public class Vampire_HellBlue extends Skill {
	public Vampire_HellBlue() {
		super("hellblue", CastingTarget.Self);
		this.getEntries().put(
				InvocationEvent.STD_IE_ON_ACTIVE,
				new InvocationEntry(
						new InvocationCondition() {

							@Override
							public boolean shouldInvoke(int rank,
									BattleActor caster, CastingTarget target,
									EventParameter ep) {
								boolean ret = !caster.hasBuff(new Vampire_HellBlue_Buff().getName());
								return ret;
							}
							
						},
						new InvocationAction() {
							@Override
							public Collection<ActionProduct> act(
									int rank, BattleActor caster,
									CastingTarget target,
									EventParameter ep) {
								
								// caster lose HP corresponding to current HP
								// caster gain 150% of Strength for 3 attack turns
								// percentage of HP loss can be calculated by 80% - ((rank - 1) * 10%);
								// Ex.	rank1 = sacrifice 80% of current HP
								//		rank2 = sacrifice 70% of current HP
								//		rank3 = sacrifice 60% of current HP
								double factor = 0.8 - ((rank - 1) * 0.1);
								int sacrifice = (int) (caster.getCurrHealth() * factor);
								
								Collection<ActionProduct> product = new ArrayList<ActionProduct>();
								Damage damageProduct = new Damage(caster, 
										caster,
										sacrifice,
										ActionValueFlag.Normal,
										ActionValueElement.Shadow);
								product.add(damageProduct);
								product.add(new ActionAddBuff(caster,
										caster,
										new Vampire_HellBlue_Buff()));
								product.add(new CombatLog(caster, caster,
										caster.getName() + " suffered %p from [" + name + "].",
										damageProduct));
								return product;
							}
						}));
	}

}